<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="${pageContext.request.contextPath }/css/base.css" />
<link rel="stylesheet" href="${pageContext.request.contextPath }/css/info-reg.css" />
<title>网上招聘系统</title>
<style type="text/css">
	.error{
		color:Red;
		font-size:13px;
		margin-left:5px;
		padding-left:16px; 
	}
</style>
</head>
<body>
<div class="title">
	<h2>企业信息注册(*为必填项)</h2>
</div>
<form id="fm">
<div class="main">
	<p class="short-input ue-clear">
    	<label>*用户名：</label>
        <input name="username" type="text"/><span id="validate"></span>
    </p>	
    <p class="short-input ue-clear">
    	<label>*密码：</label>
        <input name="password" type="password" style="width:258px;height:27px;border:1px solid #C5D6E0"/>
    </p>	
	<p class="short-input ue-clear">
    	<label>*公司名称：</label>
        <input name="companyName" type="text"/>
        </p>	
    <p class="long-input ue-clear">
    	<label>*公司地址：</label>
        <input name="location" type="text"/>
    </p>
    
    
    <div class="btn ue-clear">
		<input style="height:50px;width:150px;background-color:#68B86C;color:white;border-radius:10px" type="submit" value="提交"/>
		<input style="height:50px;width:150px;background-color:#EFF6FA;color:black;border-radius:5px" type="reset" value="清空"/>
	</div>
</div>
</form>
</body>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/WdatePicker.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.validate.min.js"></script>
<script type="text/javascript">
	
	$( "#fm" ).validate({
	      rules: {
	          username: {
	              required: true,
	              minlength: 4,
	              maxlength: 10
	          },
	          password: {
	             required:true,
	             minlength: 4,
	             maxlength: 10
	          },
	          companyName: {
		         required:true
		      },
	          location: {
		         required:true
	          }
	      },
	      
	      messages: {
	          username: {
	              required: "*不能为空！",
	              maxlength: $.validator.format( "长度不得大于10个字符！" ),
	          	  minlength: $.validator.format( "长度不得小于4个字符！" )
	          },
	          password: {
	              required: "*不能为空！",
	              maxlength: $.validator.format( "长度不得大于10个字符！" ),
	          	  minlength: $.validator.format( "长度不得小于4个字符！" )
		      },
		      companyName: {
	              required: "*不能为空！"
		      },
	          location: {
	              required: "*不能为空！"
		      }
	      },
	      submitHandler: function(form) {  
              validate();  //用自定义函数提交表单  
          } 
	  });
	
	//ajax验证用户名成功后，再进行注册	
	function validate(){
		$.ajax({
			url:"${pageContext.request.contextPath}/company/enroll.action",
			type:"post",
	        dataType:"json",
			data:$("#fm").serialize(),
			success:function(data){
				console.log(data);
				if(data.result=='fail'){
					$("#validate").html("登录名重复！");
				}else{
					alert("注册成功！");
					window.open ('${pageContext.request.contextPath}','_top');
				}
			}
		});		
	}
</script>
</html>